package com.heying.springbootweb.common;

import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.NoSuchElementException;

//@ControllerAdvice
@Slf4j
public class GlobalExceptionResolver {

    @ExceptionHandler(NoSuchElementException.class)
    private String handNoSuchElementException(Exception e, Model model){
        log.error("数据未找到",e);
        model.addAttribute("info", "该资源不存在");
        return "error";
    }

    @ExceptionHandler(FileSizeLimitExceededException.class)
    private String handleFileSizeLimitExceededException(Exception e, Model model){
        log.error("上传文件过大",e);
        model.addAttribute("info", "该资源不存在");
        return "error";
    }
}
